package com.wzs.easytobuy.cofig;

import com.wzs.easytobuy.handler.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  //定义此类为配置类(即之前的xml配置文件)
public class InterceptorConfig implements WebMvcConfigurer {

    //mvc:interceptors
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //要拦截user下所有的访问请求,必须用户登录后才可访问,
        //但是这样拦截的路径中有一些是不需要登录也可访问的
        String[] addPathPatterns = {
                "/user/**", "/product/**", "/car/**"
        };
        //要排除的路径,排除的路径,说明不需要用户登录也可访问"/static/**"
        String[] excludePathPatterns = {
                "/user/out.do", "/Index.do", "/*/Login.do", "/Register.do", "/*/login.do", "/user/register.do",
                "/test.do", "/css/**", "/css/images/**", "/images/**", "/js/**", "/jquery/**","/","/user/checkUserName.do","/user/checkEmail.do"
        };

        //mvc:intercept  bean class = ""
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);

    }
}
